1. Technical Field
The present invention relates in general to improved network systems and in particular to a method for dynamically controlling the number of active threads in a thread pool waiting for client requests from a network. Still more particularly, the present invention relates to monitoring the number of idle threads or the time requests wait in a queue and returning the monitored counts to a user application periodically, such that the number of threads waiting in a thread pool may be dynamically adjusted to more efficiently manage current loads.
2. Description of the Related Art
The development of computerized information resources, such as interconnection of computer networks, allows users of data processing systems to link with servers within a network to access vast amounts of electronic information. Multiple types of computer networks have been developed that provide different types of security and access and operate at different speeds. For example, the internet, also referred to as an “internetwork”, is a set of computer networks, possibly dissimilar, joined together by means of gateways that handle data transfer and the conversion of messages from the sending network to the protocols used by the receiving network. When capitalized, the term “Internet” refers to the collection of networks and gateways that use the TCP/IP suite of protocols.
Often times, servers accessible via the Internet provide access to applications, web pages, or databases. Further, these web servers, application servers, and database servers often handle multiple requests simultaneously. To handle a heavy load of requests, the operating system handling a server may allocate multiple active threads for each service process provided by the server. Each active thread waits to service a request from one of the multiple clients submitting requests to communicate with the server.
To distribute requests among threads, a listener socket with a listener thread is designated that listens for new requests from clients seeking to communicate with the server. When a new request is detected, the listener socket attempts to hand off the request to one of multiple idle threads. When the thread is handed off, all of the idle threads are “woken up” and one of the idle threads is selected to handle the request. Waking up all of the idle threads each time a request is received uses significant processing resources. For example, if 1000 threads are invoked for a particular process and only 100 are currently servicing requests from clients, the next request will wake up 900 threads and execute 3 system calls for each thread woken up, for only one of those threads to accept and handle the request. Therefore, it is advantageous to limit the number of threads invoked in a thread pool so as to limit the number of idle threads.
By limiting the number of idle threads, however, some requests may not be serviced when received. Requiring clients to wait until a thread is available may lead to unacceptable wait times for processing client requests. For example, if only 100 threads are invoked for a particular process and all are currently servicing requests from clients when 100 more requests on average are received, a request queue that holds waiting requests may be overrun and the time that requests in the queue wait for a thread may be unacceptable. Therefore, it is also advantageous to maintain sufficient idle threads such that wait times are not prohibitive for clients seeking services from a server. Accordingly, it would be advantageous to provide a method, system, and program for monitoring the number of idle threads over a period of time and the number of requests waiting to be serviced over a period of time, such that the number of threads in a pool can be dynamically increased or decreased within a defined range according to the current load needs of the server.